'use strict';

module.exports = app => {
    class HomeController extends app.Controller {

        //首页
        async index() {
            const data = await this.service.home.index();
            const length = data.banner.length;
            const mark = length - 1;
            const arrmark = [mark];
            const task = await this.service.home.task();
            await this.ctx.render("/index/index", {data,task,length,arrmark});
            
        };

        //更多咨询
        async newslist(){
            const data = await this.service.home.newslist();
            await this.ctx.render("/index/news-list.html",{data});
        }

        //资讯详情
        async eduDetail(){
            if ('GET' == this.ctx.request.method){
                const params = this.ctx.request.query;
                this.app.logger.info(params);
                const data = await this.service.home.eduDetail(params);
                const comment = await this.service.comment.getComment(params);
                this.app.logger.info(data);
                this.app.logger.info(comment);
                await this.ctx.render("/content/information.html", {data,comment});

            }else{
                const param = this.ctx.request.body;
                const post = await this.service.comment.setComment(param);
                this.success();
            }

        };
    }
    return HomeController;
};

